package com.finance.system.support.utils;

import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

public class DomainTransHelper {

    public static <T> T transFromTo(Object from,Class<T> clazz){
        try {
            T to = clazz.newInstance();
            BeanUtils.copyProperties(from,to);
            return to;
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;

    }

    public static <T> List transBatchFromTo(List<Object> from, Class<T> clazz){
        ArrayList<T> list = new ArrayList<>();
        for (Object o : from) {
            T t = transFromTo(o, clazz);
            list.add(t);
        }
        return list;

    }

}
